package com.lyj.io.module.data.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lyj.io.common.utils.DateUtil;
import com.lyj.io.common.utils.PageUtils;
import com.lyj.io.common.utils.Query;
import com.lyj.io.module.data.dao.TabFieldDao;
import com.lyj.io.module.data.entity.TabFieldEntity;
import com.lyj.io.module.data.entity.TabsEntity;
import com.lyj.io.module.data.service.TabFieldService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 模型字段相关接口
 * @author: 李亚杰
 * @version: 1.0
 * @date: 2021/8/19 14:31
 */
@Service("tabFieldService")
public class TabFieldServiceImpl extends ServiceImpl<TabFieldDao, TabFieldEntity> implements TabFieldService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<TabFieldEntity> queryWrapper = new QueryWrapper<TabFieldEntity>();
        queryWrapper.eq("delete_flag", "0");
        queryWrapper.eq("related_tab_id", params.get("relatedTabId"));
        IPage<TabFieldEntity> page = this.page(
                new Query<TabFieldEntity>().getPage(params),
                queryWrapper
        );
        return new PageUtils(page);
    }

    @Override
    public List<TabFieldEntity> getByrelatedTabId(Long relatedTabId) {
        QueryWrapper<TabFieldEntity> queryWrapper = new QueryWrapper<TabFieldEntity>();
        queryWrapper.eq("delete_flag", "0");
        queryWrapper.eq("related_tab_id", relatedTabId);
        return this.baseMapper.selectList(queryWrapper);
    }

    @Override
    public void removeByIds(List<String> ids) {
        UpdateWrapper<TabFieldEntity> updateWrapper = new UpdateWrapper<>();
        updateWrapper.in("id", ids);
        updateWrapper.set("delete_flag", DateUtil.format2String(DateUtil.YYYYMMDDHHMMSS, new Date()));
        this.baseMapper.update(null ,updateWrapper);
    }
}
